package top.superflow.flow.config

import com.fasterxml.jackson.annotation.JsonProperty
import top.superflow.core.api.Aliasable
import top.superflow.core.metadata.MetadataAble
import top.superflow.lang.{CollectionUtils, StringUtils}

import scala.beans.BeanProperty
import scala.collection.mutable.{Set => MSet}

trait Identifiable extends MetadataAble with Aliasable with Cloneable{

  @BeanProperty
  var key : String = _

  @BeanProperty
  var tags : MSet[String] = MSet()

  @BeanProperty
  var description : String = _

  @BeanProperty
  var group : String = _

  @BeanProperty
  var visibleLevel : String = _

  def addTag (t : String): Unit = {
    if(StringUtils.isBlank(t)){
      return;
    }

    if(this.tags == null){
      this.tags = MSet()
    }

    this.tags += t
  }

  @JsonProperty("tags")
  def setTags (ts : Array[String]): Unit = {
    if(CollectionUtils.isEmpty(ts)){
      return;
    }

    this.tags = MSet()

    this.tags ++= ts.toSet
  }

  def copyId(identity : Identifiable) : Unit = {
    if(identity == null) return;
    
    this.setKey(identity.getKey)
    this.setTags(identity.getTags)
    this.setDescription(identity.getDescription)
    this.setGroup(identity.getGroup)
    this.mergeMetadata(identity.getMetadata)
  }

}